widget-factory: Add a scale to the gear menu
authorMatthias Clasen <mclasen@redhat.com>
Mon, 26 Oct 2020 16:58:23 +0000 (12:58 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 27 Oct 2020 02:43:12 +0000 (22:43 -0400)
This tests the custom menuitem support, and lets you
control the transition duration for the main stack.

demos/widget-factory/widget-factory.c
demos/widget-factory/widget-factory.ui

index 021b69e6401da81a5b4aac13b0a329a2632ef427..1d81031a8e9fd0f24bad98f5e43760d1c797b502 100644 (file)
@@ -91,6 +91,16 @@ change_theme_state (GSimpleAction *action,
 
 static GtkWidget *page_stack;
 
+static void
+transition_speed_changed (GtkRange *range,
+                          gpointer  data)
+{
+  double value;
+
+  value = gtk_range_get_value (range);
+  gtk_stack_set_transition_duration (GTK_STACK (page_stack), (int)value);
+}
+
 static void
 change_transition_state (GSimpleAction *action,
                          GVariant      *state,
@@ -2022,6 +2032,7 @@ activate (GApplication *app)
           "validate_more_details", (GCallback)validate_more_details,
           "mode_switch_state_set", (GCallback)mode_switch_state_set,
           "level_scale_value_changed", (GCallback)level_scale_value_changed,
+          "transition_speed_changed", (GCallback)transition_speed_changed,
           NULL);
   gtk_builder_set_scope (builder, scope);
   g_object_unref (scope);
index 0b383655ee7c9a8d99d6f54b3bdd8ba608d2d2ae..36bee582cf14d354d87ac58d5b82fe8a1b46c719 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <menu id="gear_menu">
+  <menu id="gear_menu_model">
     <section>
       <item>
         <attribute name="label" translatable="yes">Get Busy</attribute>
@@ -40,6 +40,9 @@
         <attribute name="label" translatable="yes">Transition Pages</attribute>
         <attribute name="action">win.transition</attribute>
       </item>
+      <item>
+        <attribute name="custom">transition-speed</attribute>
+      </item>
     </section>
     <section>
       <item>
@@ -444,7 +447,26 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
         <child type="end">
           <object class="GtkMenuButton" id="gear_menu_button">
             <property name="valign">center</property>
-            <property name="menu-model">gear_menu</property>
+            <property name="popover">
+              <object class="GtkPopoverMenu" id="gear_menu">
+                <property name="menu-model">gear_menu_model</property>
+                <child type="transition-speed">
+                  <object class="GtkScale">
+                    <property name="adjustment">
+                      <object class="GtkAdjustment">
+                        <property name="lower">0</property>
+                        <property name="upper">1000</property>
+                        <property name="value">250</property>
+                        <property name="step-increment">50</property>
+                        <property name="page-increment">50</property>
+                        <property name="page-size">0</property>
+                      </object>
+                    </property>
+                    <signal name="value-changed" handler="transition_speed_changed"/>
+                  </object>
+                </child>
+              </object>
+            </property>
             <property name="icon-name">open-menu-symbolic</property>
           </object>
         </child>